package com.asion.gankapp.presenter;

import com.asion.gankapp.entrys.BaseEntry;
import com.asion.gankapp.model.AllTypeModel;
import com.asion.gankapp.model.SearchModel;
import com.asion.gankapp.view.BaseView;

/**
 * Created by asion on 16-10-6.
 */

public class SearchPresenter  implements BasePresenter {
    private BaseView baseView;
    private SearchModel searchModel;

    public SearchPresenter(BaseView baseView) {
        this.baseView = baseView;
        searchModel = new SearchModel();
        baseView.setPresenter(this);
    }

    @Override
    public void start(Object type, int page) {
        if(0 >= page){
            setRandomData();
        }else{
            setQurryData(((String) type),page);
        }
    }

    public void setQurryData(String type,int page){
        searchModel.getQurryData(type, page, new AllTypeModel.OnGetEntryDatas() {
            @Override
            public void onGetEntrySuccess(Object object) {
                baseView.showAllTypeSuccess(((BaseEntry) object));
            }

            @Override
            public void onGetEntryError(String string) {
                baseView.showAllTypeError(string);
            }
        });
    }

    public void setRandomData(){
        searchModel.getRandomData(new AllTypeModel.OnGetEntryDatas() {
            @Override
            public void onGetEntrySuccess(Object object) {
                baseView.showAllTypeSuccess(((BaseEntry) object));
            }
            @Override
            public void onGetEntryError(String string) {
                baseView.showAllTypeError(string);
            }
            });
    }

}
